package com.example.socialwebserver.controller;

import com.example.socialwebserver.pojo.*;
import com.example.socialwebserver.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin//告诉浏览器，允许别的网站访问我
public class UserController {
    @Autowired
    UserService userService;

    @RequestMapping("/user/SelectAll")
    public ServerResult SelectAll(){
        List<UserDAO> userDaos = userService.SelectAll();
        ServerResult serverResult = new ServerResult(0,"查询成功",userDaos);
        return serverResult;
    }
    @RequestMapping("/user/SelectById")
    public ServerResult SelectById(Integer id){
        UserVO userVO = userService.SelectById(id);
        ServerResult serverResult = new ServerResult(0,"成功",userVO);
        return serverResult;
    }


    @RequestMapping("/user/updateUser")
    public ServerResult updateUser(UserDAO userDAO){
        boolean b = userService.UpdateById(userDAO);
        return b== true?new ServerResult(0,"修改用户信息成功",b):new ServerResult(-1,"修改用户信息失败",b);
    }
    @RequestMapping("/user/deleteUser")
    public ServerResult DeleteById(Integer id){
        boolean b = userService.DeleteById(id);
        return b== true?new ServerResult(0,"删除用户信息成功",b):new ServerResult(-1,"删除用户信息失败",b);
    }

}
